package com.gzhryc.shared_device.oem.micro.queue.handlers.order;

import com.gzhryc.common.event.AbsDelayHandler;
import com.gzhryc.common.logging.Logger;
import com.gzhryc.shared_device.oem.code.member.dao.db.MemberBusinessOrder;
import com.gzhryc.shared_device.oem.code.member.services.MemberBusinessOrderService;
import com.gzhryc.shared_device.oem.code.order.event.OrderCreateEvent;
import com.gzhryc.shared_device.oem.code.place.dao.db.PlacePhysicalStore;
import com.gzhryc.shared_device.oem.code.place.services.PlacePhysicalStoreService;
import com.gzhryc.shared_device.oem.code.profit.service.BusinessOrderUserService;

public class OrderCreateEventHandler extends AbsDelayHandler<OrderCreateEvent> {

    static Logger log = Logger.getLogger(OrderCreateEventHandler.class);

    @Override
    public boolean execute(OrderCreateEvent event) {
        log.info("订单创建事件，信息：{{0:json}}",event);
        try {
            MemberBusinessOrder businessOrder = MemberBusinessOrderService.self(event.getCreateDate()).getByTradeNo(event.getTradeNo());
            PlacePhysicalStore physicalStore = PlacePhysicalStoreService.self().getById(businessOrder.getPlaceId());
            BusinessOrderUserService.self(businessOrder.getCreateDate()).add(businessOrder, physicalStore.getUserId());
        }catch (Exception e){
            log.error(e.getMessage(),e);
        }
        return true;
    }
}
